/*
 * @Description:
 * @Author: Haor
 * @Date: 2022-03-31 20:37:58
 * @LastEditTime: 2022-05-07 13:00:49
 * @LastEditors: Haor
 */
import { Controller, Get, Post, Body, Param, UseGuards, Req } from "@nestjs/common";
import { Request } from 'express'
import { AuthService } from './auth.service'
import { AuthLoginDto } from './dto/auth-login.dto'
import { NoAuth, NoSign } from '@decorators'
import { JwtAuthGuard } from "@guards/jwt.auth.guard";
import { LocalAuthGuard } from "@guards/local.auth.guard";
import { AuthGuard } from "@nestjs/passport";

@Controller('auth')
export class AuthController {
	constructor(
	    private readonly authService: AuthService
    ) {}

	// 登录
    @Post('/login')
    @NoAuth()
	login(@Body() authLoginDto: AuthLoginDto, @Req() req: Request){
		return this.authService.login(authLoginDto)
	}

    /**
     * 退出登录
     */
    @Post('/logout')
    logout(@Req() req: Request) {
	    return this.authService.logout(+req.user['userId'])
    }

    /**
     * 获取token
     */
	@Post('/refreshToken')
	refreshToken() {
		return 'ok'
	}

	/**
	 * 获取随机二维码
	 */
	@NoAuth()
	@NoSign()
	@Get('/captcha')
	getCaptcha() {
		return this.authService.getCaptcha()
	}

	// 校验 token
	verifyToken(token: string): number {
		return 111
	}

	@Get('/info')
	getUser(@Req() req: Request) {
        return this.authService.getLoginUser(+(req.user['userId']))
    }

    @Post('/build_menu')
    buildMenu(@Req() req: Request) {
	    const userId: number  = +req.user['userId'] // 登录用户
        return this.authService.buildMenu(userId)
    }
}
